package com.bear.cli.command;

import cn.hutool.core.bean.BeanUtil;
import com.bear.generator.MainGenerator;
import com.bear.model.MainTemplateConfig;
import lombok.Data;
import picocli.CommandLine.*;
import picocli.CommandLine.Command;

import java.util.concurrent.Callable;

/**
 * @Author : bear
 * Description :
 * @Create : 2024/11/12 - 19:34
 */
@Command(name = "generate",description = "生成代码",mixinStandardHelpOptions = true)
@Data
public class GenerateCommand implements Callable {
    /**
     * 是否生成循环
     */
    @Option(names = {"-l","--loop"},arity = "0..1",description = "是否循环",interactive = true,echo = true)
    private boolean loop;

    /**
     * 作者
     */
    @Option(names = {"-a","--author"},arity = "0..1",description = "作者",interactive = true,echo = true)
    private String author = "bear";

    /**
     * 输出信息
     */
    @Option(names = {"-o","--outputText"},arity = "0..1",description = "输出文本",interactive = true,echo = true)
    private String outputText = "sum = ";
    @Override
    public Object call() throws Exception {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        //将当前对象的属性值复制给mainTemplateConfig对象中
        BeanUtil.copyProperties(this,mainTemplateConfig);
        System.out.println("配置信息："+mainTemplateConfig);
        //动静结合生成文件
        MainGenerator.doGenerate(mainTemplateConfig);
        return 0;
    }
}
